<template>
  <vxe-grid ref="xTable" v-bind="gridOptions" />
</template>

<script lang="ts">
  import { Select } from 'ant-design-vue';
  import { defineComponent, PropType, reactive, ref, watch } from 'vue';
  import { VxeGridInstance, VxeGridProps } from 'vxe-table';
  import 'xe-utils';
  import { ColumnItem } from '../api/model';
  import { getColumn } from './config';
  export default defineComponent({
    components: { ASelect: Select },
    props: {
      dataSource: {
        type: [Array] as PropType<ColumnItem[]>,
        default: null,
      },
    },
    setup(props, _) {
      const columnTable = reactive({
        loading: false,
      });
      const xTable = ref({} as VxeGridInstance);
      const gridOptions = reactive({
        border: 'outer',
        showOverflow: true,
        loading: columnTable.loading,
        stripe: true,
        maxHeight: '500px',
        columnConfig: {
          width: '120px',
        },
        size: 'small',
        editConfig: {
          trigger: 'click',
          mode: 'row',
          showIcon: false,
        },
        columns: getColumn('edit'),
      } as VxeGridProps);
      watch(
        () => props.dataSource,
        (val) => {
          xTable.value?.loadData(val);
        },
      );
      function getData() {
        return xTable.value?.getData();
      }
      return {
        xTable,
        gridOptions,
        columnTable,
        getData,
      };
    },
  });
</script>
